import numpy as np
from matplotlib import pyplot as plt 

plt.figure(figsize = (6, 8), dpi = 200) # create a frame, dpi = 200
plt.subplot(111)    #create a subgraph, grid = 1 * 1


colors = ['blue', 'red', 'purple']

def gen(scale, offset):
    s = 50
    x = np.linspace(50, 200, s)
    x = np.reshape(x, (s, 1))
    y = x * scale + offset
    y += np.reshape(np.random.randint(-10, 10, size=s), (s, 1))
    return x, y

def cal(mi, ce, ma, mip, map, cep, scale_l, scale_r, color):
    xx0 = np.linspace(mi, ce, scale_l * 2, endpoint = True)   # x range changed
    x0 = (xx0 - ce) / (ce - mi) * scale_l

    xx1 = np.linspace(ce, ma, scale_r * 20, endpoint = True)
    x1 = (xx1 - ce) / (ma - ce) * scale_r
    x = np.append(x0, x1)
    y = np.arctan(x * 2)
    z = np.arctan(x * 1.8)
    # a = np.arctan(x)


    a0 = np.arctan(x0) * 2 / np.pi * (cep - mip) + cep

    a1 = np.arctan(x1) * 2 / np.pi * (map - cep) + cep

    # print(np.append(x0, x1))
    # print(np.append(a0, a1))
    # exit(0)
    # plt.plot(x, y, color = 'blue', label = 'scale=2',linewidth = 1.0, linestyle= '--')      #define line color and style
    # plt.plot(x, z, color = 'red', label = 'scale=1.8',linewidth = 1.0, linestyle= '--') 
    plt.plot(np.append(xx0, xx1), np.append(a0, a1), color, label = 'scale=1', linewidth = 1.0, linestyle= '--')

    xx = np.append(xx0, xx1)
    aa = np.append(a0, a1)
    p = 50
    offsets = np.random.rand(p * len(aa))
    xs = [(xx[int(i / p)]) for i in range(len(xx) * p)]
    ys = [(aa[int(i / p)]) for i in range(len(aa) * p)] + (offsets - 0.5) * 100
    print(ys)
    plt.scatter(xs, ys, 2)

# for i in range(len(mips)):
#     cal(mi, ce, ma, mips[i], maps[i], ceps[i], scale_l, scale_r, colors[i])

# plt.xlim(0, 300)     #limit x range
# # plt.ylim(-np.pi/2, np.pi/2)     #limit y range
# plt.ylim(0, 50000)     #limit y range

# plt.xticks([40, 100, 200])   # 5 values in x-axis
# # plt.yticks([-np.pi/2, -0.75, 0.75, np.pi/2],[r'$-\pi/2$',r'$-0.75$',r'$0.75$',r'$\pi/2$'])   # 4 values in y_axis
# plt.yticks(ps)   # 4 values in y_axis

# #move the boundary line,set origin is 0
# # plt.axis('equal')       #x-axis and y-axis scale equally
# ax = plt.gca()  #get current line position
# # ax.xaxis.set_ticks_position('bottom')       
# # ax.yaxis.set_ticks_position('left')
# # ax.spines['bottom'].set_position(('data', mip))  #set bottom position to 0
# # ax.spines['left'].set_position(('data', mi))
# # ax.spines['top'].set_color('none')      #cancel original boundary
# # ax.spines['right'].set_color('none')

# # plt.legend(loc = 'upper left')

# plt.show()